<%-- 
    Document   : AddToCart
    Created on : Nov 20, 2012, 5:48:04 PM
    Author     : tuan
--%>


<%@page import="data.OrderDAL"%>
<%@page import="data.Order"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.Iterator"%>
<%@page import="data.ProductDAL"%>
<%@page import="java.util.Collection"%>
<%@page import="data.ProductEntity"%>
<%@page import="java.util.Enumeration"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <div class="page secondary">
            <div class="page-header">
                <div class="page-header-content">
                    <h1>Add to cart successfully!</h1>
                </div>
            </div>
            <%
                String productId = request.getParameter("proID");
                if (productId != null) {
                    Collection<Order> orders = (Collection<Order>) session.getAttribute("orders");
                    if(orders.isEmpty()){
                        Order order = new Order(productId, 1);
                        
                        orders.add(order);
                    }else{
                    if (!OrderDAL.check(productId, orders)){
                        
                        session.setAttribute("orders", OrderDAL.searchById(productId, orders));
                    }
                } 
                                       }
            %>
            <div class="page-region">
                <div class="page-region-content">
                    <div class="span8">
                        <a href="ViewCart.jsp" class="button">View shopping cart!</a>
                        <a href="viewProduct.jsp" class="button">Home Page</a>
                    </div>
                </div>
            </div>
        </div>
    </body>
</html>
